#define ElemType int

typedef struct ListNode List_Node;

#include "common.h"

int* findAnagrams(char* s, char* p, int* returnSize);

int main()
{
	int* returnSize = malloc(sizeof(int));
	char s[30001] = { 0 };
	char p[30001] = { 0 };
	scanf("%s", &s);
	scanf("%s", &p);
	int* res = findAnagrams(s, p, returnSize);
	for (int i = 0, len = *returnSize; i < len; i++)
		printf("%d\t", res[i]);
	free(res);
	return 0;
}

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* findAnagrams(char* s, char* p, int* returnSize)
{
	int len_s = strlen(s), len_p = strlen(p);
	if (len_s < len_p) {
		*returnSize = 0;
		return NULL;
	}
	int* res = calloc(len_s, sizeof(int));
	int size = 0;

	short* freq_p = calloc(26, sizeof(short));
	int bitmap_p = 0;
	for (int i = 0; i < len_p; i++)
		freq_p[p[i] - 'a']++;
	for (int i = 0; i < 26; i++)
		if (freq_p[i] > 0)
			bitmap_p |= 1 << i;

	for (int i = 0; i < len_p; i++) {
		int bias = s[i] - 'a';
		short cur_val = --freq_p[bias];
		if (cur_val == 0 || cur_val == -1)
			bitmap_p ^= 1 << bias;
	}
	if (bitmap_p == 0)
		res[size++] = 0;

	for (int hi = len_p, lo = 0; hi < len_s; hi++, lo++) {
		int bias_lo = s[lo] - 'a', bias_hi = s[hi] - 'a';
		int lo_val = ++freq_p[bias_lo], hi_val = --freq_p[bias_hi];
		if (lo_val == 0 || lo_val == 1)
			bitmap_p ^= 1 << bias_lo;
		if (hi_val == -1 || hi_val == 0)
			bitmap_p ^= 1 << bias_hi;
		if (bitmap_p == 0)
			res[size++] = lo + 1;
	}

	*returnSize = size;
	res = realloc(res, size * sizeof(int));
	return res;
}
